<!-- FollowMessage.vue -->
<template>
  <div class="follow-message">
    <h3>关注消息</h3>
    <div v-if="messages.length === 0" class="no-messages">暂无关注消息</div>
    <div v-for="msg in messages" :key="msg.notificationId" class="follow-item">
      <img :src="msg.followerAvatar" :alt="msg.followerName" class="avatar" />
      <div class="follow-info">
        <p><strong>{{ msg.followerName }}</strong> 关注了你</p>
        <small>{{ formatDate(msg.followTime) }}</small>
      </div>
      <button @click="markRead(msg.notificationId)" v-if="!msg.isRead">标记已读</button>
    </div>
  </div>
</template>

<script>
export default {
  props: {
    messages: {
      type: Array,
      required: true
    }
  },
  methods: {
    markRead(notificationId) {
      this.$emit('mark-read', notificationId);
    },
    formatDate(date) {
      const hours = String(date.getHours()).padStart(2, '0');
      const minutes = String(date.getMinutes()).padStart(2, '0');
      return `${hours}:${minutes}`;
    }
  }
};
</script>

<style scoped>
.follow-message {
  padding: 20px;
  background: #fff;
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}

.follow-item {
  display: flex;
  align-items: center;
  padding: 12px 0;
  border-bottom: 1px solid #eee;
}

.avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  margin-right: 12px;
}

.follow-info {
  flex: 1;
}

.no-messages {
  color: #999;
  font-style: italic;
}
</style>